import cv2
import os

def readImg(filepath):              #遍历文件夹
    allimg = []
    pathDir=os.listdir(filepath)
    for  allDir in pathDir:
          child=os.path.join('%s%s'%(filepath,allDir))
          img=cv2.imread(child)
          allimg.append(img)
    return allimg                  #返回图像list

def stitcher(allimg):                  #拼接图片
    stitcher = cv2.createStitcher(False)
    result = stitcher.stitch(allimg)
    cv2.imshow('result',result[1])
    cv2.waitKey(0)
    cv2.imwrite('C:/Users/DELL/Desktop/hhh/result2.jpg', result[1])

if __name__=='__main__':
    filepath='C:/Users/DELL/Desktop/hhhh/'    #输入文件夹
    allimg=readImg(filepath)
    stitcher(allimg)